﻿// Decompiled with JetBrains decompiler
// Type: System.Web.Razor.StateMachine`1
// Assembly: System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// MVID: 682513D6-F37E-48AC-9909-F3EE103CFF14
// Assembly location: D:\Project\Idea\无人机外网\uav\客户端工程\排查工具\bin\Release\System.Web.Razor.dll

namespace System.Web.Razor
{
  /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Represents the state of the machine.</summary>
  /// <typeparam name="TReturn">The generic type Return.</typeparam>
  public abstract class StateMachine<TReturn>
  {
    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Gets the starting state of the machine.</summary>
    /// <returns>The starting state of the machine.</returns>
    protected abstract StateMachine<TReturn>.State StartState { get; }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Gets or sets the current state of the machine.</summary>
    /// <returns>The current state of the machine.</returns>
    protected StateMachine<TReturn>.State CurrentState { get; set; }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Describes the turning process of the state.</summary>
    /// <returns>The turning process of the state.</returns>
    protected virtual TReturn Turn()
    {
      if (this.CurrentState == null)
        return default (TReturn);
      StateMachine<TReturn>.StateResult stateResult;
      do
      {
        stateResult = this.CurrentState();
        this.CurrentState = stateResult.Next;
      }
      while (stateResult != null && !stateResult.HasOutput);
      return stateResult == null ? default (TReturn) : stateResult.Output;
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Disables the machine upon transition.</summary>
    /// <returns>The machine to stop.</returns>
    protected StateMachine<TReturn>.StateResult Stop() => (StateMachine<TReturn>.StateResult) null;

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Indicates the new transition of the state.</summary>
    /// <returns>The new transition of the state.</returns>
    /// <param name="newState">The new state.</param>
    protected StateMachine<TReturn>.StateResult Transition(
      StateMachine<TReturn>.State newState)
    {
      return new StateMachine<TReturn>.StateResult(newState);
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Indicates the new transition of the state with the specified output.</summary>
    /// <returns>The new transition of the state with the specified output.</returns>
    /// <param name="output">The output.</param>
    /// <param name="newState">The new state.</param>
    protected StateMachine<TReturn>.StateResult Transition(
      TReturn output,
      StateMachine<TReturn>.State newState)
    {
      return new StateMachine<TReturn>.StateResult(output, newState);
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Stays into the machine during the transition.</summary>
    /// <returns>Transition of the state machine.</returns>
    protected StateMachine<TReturn>.StateResult Stay() => new StateMachine<TReturn>.StateResult(this.CurrentState);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Stays into the machine during the transition with the specified output.</summary>
    /// <returns>The output of the transition.</returns>
    /// <param name="output">The output.</param>
    protected StateMachine<TReturn>.StateResult Stay(TReturn output) => new StateMachine<TReturn>.StateResult(output, this.CurrentState);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.</summary>
    public delegate StateMachine<TReturn>.StateResult State();

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Represents the state result.</summary>
    public class StateResult
    {
      /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Initializes a new instance of the <see cref="T:System.Web.Razor.StateMachine`1.StateResult" /> class.</summary>
      /// <param name="next">The next output.</param>
      public StateResult(StateMachine<TReturn>.State next)
      {
        this.HasOutput = false;
        this.Next = next;
      }

      /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Initializes a new instance of the <see cref="T:System.Web.Razor.StateMachine`1.StateResult" /> class.</summary>
      /// <param name="output">The output.</param>
      /// <param name="next">The next state.</param>
      public StateResult(TReturn output, StateMachine<TReturn>.State next)
      {
        this.HasOutput = true;
        this.Output = output;
        this.Next = next;
      }

      /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Gets or sets a value indicating whether the state has output.</summary>
      /// <returns>true if the state has output; otherwise, false.</returns>
      public bool HasOutput { get; set; }

      /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Gets or sets the output.</summary>
      /// <returns>The <see cref="T:System.Web.Razor.StateMachine`1.State" /> representing the output.</returns>
      public TReturn Output { get; set; }

      /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Gets or sets the next state in the machine.</summary>
      /// <returns>The next state in the machine.</returns>
      public StateMachine<TReturn>.State Next { get; set; }
    }
  }
}
